package models.base;

import play.mvc.Http;

import java.util.Iterator;
import java.util.Map;

public class RequestUtility {
    public RequestUtility() {
    }

    public static String getScheme() {
        Http.Request request = Http.Request.current();
        return request.getBase().substring(0, request.getBase().indexOf(58));
    }

    public static String getBase() {
        Http.Request request = Http.Request.current();
        return String.format("%s%s", request.domain, request.port != 80 && request.port != 443 ? ":" + request.port : "");
    }

    public static boolean isIE() {
        Http.Request request = Http.Request.current();
        Http.Header uaHeader = (Http.Header)request.headers.get("user-agent");
        return uaHeader != null && uaHeader.value().contains("MSIE");
    }

    public static String getHeaderIgnoreCase(String headerName) {
        Http.Request request = Http.Request.current();
        Map<String, Http.Header> headers = request.headers;
        Iterator var3 = headers.keySet().iterator();

        String name;
        do {
            if (!var3.hasNext()) {
                return null;
            }

            name = (String)var3.next();
        } while(!headerName.equalsIgnoreCase(name));

        return ((Http.Header)headers.get(name)).value();
    }
}
